<?php
require '../vendor/autoload.php';

$key = '7c38d119-3c88-4dc1-b8a6-b2193ae6c381';

sendTextMessage($key);
sendImageMessage($key);
sendMarkdownMessage($key);
sendMarkdownContent($key);
sendNewsMessage($key);
sendFileMessage($key);


function sendTextMessage($key)
{
    $msg = new \Jxzsxsp\WechatRobot\Text\TextMessage($key);

    $msg->content = '测试消息';
    $msg->mentioned_mobile_list = ['13387057301', '@all'];

    return $msg->send();
}

function sendImageMessage($key)
{
    $msg = new \Jxzsxsp\WechatRobot\Image\ImageMessage($key);

    $msg->base64 = base64_encode(file_get_contents('test_pic_msg1.png'));
    $msg->md5 = md5_file('test_pic_msg1.png');

    return $msg->send();
}

function sendMarkdownMessage($key)
{
    $msg = new \Jxzsxsp\WechatRobot\Markdown\MarkdownMessage($key);

    $msg->content = "实时新增用户反馈<font color=\"warning\">132例</font>，请相关同事注意。 \n >类型:<font color=\"comment\">用户反馈</font> \n >普通用户反馈:<font color=\"comment\">117例</font> \n >VIP用户反馈:<font color=\"comment\">15例</font>";

    return $msg->send();
}

function sendMarkdownContent($key)
{
    $msg = new \Jxzsxsp\WechatRobot\Markdown\MarkdownMessage($key);

    $msg->appendTitle('这是标题');
    $msg->append('实时新增用户反馈');
    $msg->appendColor('132例', 'warning');
    $msg->append('，请相关同事注意。');
    $msg->appendReference('类型:');
    $msg->appendColor('用户反馈', 'comment');
    $msg->appendReference('普通用户反馈:');
    $msg->appendColor('117例', 'comment');
    $msg->appendReference('VIP用户反馈:');
    $msg->appendColor('15例', 'comment');
    $msg->appendEnter(2);
    $msg->appendLink('www.qq.com', '点击链接查看详情');
    $msg->appendEnter();
    $msg->appendBold('代码：');
    $msg->appendCode('c = a + b;');

    return $msg->send();
}

function sendNewsMessage($key)
{
    $msg = new \Jxzsxsp\WechatRobot\News\NewsMessage($key);

    $article = new \Jxzsxsp\WechatRobot\News\Article();
    $article->title = '中秋节礼品领取';
    $article->description = '今年中秋节公司有豪礼相送';
    $article->url = 'www.qq.com';
    $article->picurl = 'http://res.mail.qq.com/node/ww/wwopenmng/images/independent/doc/test_pic_msg1.png';

    $articles[] = $article;

    $msg->articles = $articles;

    return $msg->send();
}

function sendFileMessage($key)
{
    $filepath = realpath('testfile.txt');
    $upload = new \Jxzsxsp\WechatRobot\File\Upload($key, $filepath);
    $res = $upload->upload();
    $msg = new \Jxzsxsp\WechatRobot\File\FileMessage($key);
    $msg->media_id = $res['media_id'];
    return $msg->send();
}